/**
 * Copyright (c) 2012 Fujian FUNO Mobile Communication Technology Co., Ltd.
 * All rights reserved by FUNO.
 */
package com.funo.ehealth.util;

import org.apache.commons.lang.StringUtils;

/** 
 * 字符串处理类
 * 
 * @version V1.1
 * @author zhangguangying
 * @date 2012-11-16
 */
public class StringUtil {

	/**
	 * 将pattern字符串中的"{}"占位符,替换成传入的参数params[index]
	 * 
	 * @param pattern
	 *            待处理的字符串
	 * @param params
	 *            参数数组
	 * @return String
	 */
	public static String handleString(String pattern, Object... params) {
		if (null == pattern || pattern.trim().length() == 0) {
			return pattern;
		}

		if (null == params || params.length == 0) {
			return pattern;
		}
		for (int i = 0; i < params.length; i++) {
			if (null == params[i]) {
				params[i] = "null";
			}
			pattern = StringUtils.replaceOnce(pattern, "{}", params[i].toString());
		}

		return pattern;
	}
}
